﻿using Microsoft.AspNetCore.Mvc;

namespace EC.Admin.Controllers
{
    using EC.Application.Interface;
    using EC.Entity.Enum;
    using EC.Entity.Query;
    using EC.Entity.Request.Bank;
    using EC.Entity.Request.IpTable;
    using EC.Util;
    using System.Net.Http;

    public class IpTableController : BaseController
    {
        private readonly IPTableService _ipTableService;

        public IpTableController(IPTableService ipTableService, LoginService loginService) : base(loginService)
        {
            _ipTableService = ipTableService;
        }

        public IActionResult IpList()
        {
            ViewBag.SystemType = EnumUtil.ToDictionary(typeof(SystemType));

            return View();
        }

        public IActionResult Edit()
        {
            ViewBag.SystemType = EnumUtil.ToDictionary(typeof(SystemType));
            return View();
        }


        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="query">查询条件</param>
        /// <returns>PagedList<UserResponse></returns>
        public IActionResult IpListQuery(IpTableQuery query)
        {
            var list = _ipTableService.GetPager(query);

            return Json(list);
        }


        public IActionResult EditIpTable(int id)
        {
            var model = _ipTableService.Get(id);
            ViewBag.SystemType = EnumUtil.ToDictionary(typeof(SystemType));

            return View("Edit", model);
        }



        [HttpPost]
        public JsonResult SaveIpTable(SaveIpTableRequest request)
        {
            request.UserId = UserId;
            var response = _ipTableService.SaveIpTable(request);

            return Json(response);
        }



        [HttpPost]
        public JsonResult DelIpTable(int Id)
        {
            var response = _ipTableService.DelIpTable(Id);

            return Json(response);
        }

    }
}
